﻿using Core;
using UnityEngine;
using System.Collections;

namespace Core
{
    internal class MonoSystem : EntitySystem, IAwake
    {
        private MonoBehaviour initMono;

        public void Awake()
        {
            initMono = GameObject.FindObjectOfType<GameInit>();

            Subscribe<StartCoroutine>(StartCoroutine);
            Subscribe<GetInitMono>(GetInitMono);
        }

        private void GetInitMono(ref GetInitMono data)
        {
            data.mono = initMono;
        }

        private void StartCoroutine(ref StartCoroutine data)
        {
            if (initMono == null)
            {
                Debug.LogError("gameMono is null");
                return;
            }

            data.coroutine = initMono.StartCoroutine(data.handler);
        }
    }

    internal struct GetInitMono : IEventData
    {
        public MonoBehaviour mono;
    }
}
